<script>
    //定义服务端
    window.UEDITOR_SERVER_URL = "{url url='/cms/ueditor'}";
</script>
<script src="{static url='/third-party/ueditor1.4.3/ueditor.config.js'}"></script>
<script src="{static url='/third-party/ueditor1.4.3/ueditor.all.js'}"></script>
<script src="{static url='/third-party/ueditor1.4.3/lang/zh-cn/zh-cn.js'}"></script>
<script>
    //编辑器工具栏
    window.UEDITOR_CONFIG.toolbars = [
        [
            'fullscreen', 'source', '|', 'undo', 'redo',
            '|',
            'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify',
            '|',
            'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript',
            '|',
            'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc',
            '|',
            'rowspacingtop', 'rowspacingbottom', 'lineheight',
            '|',
            'customstyle', 'paragraph', 'fontfamily', 'fontsize', 'insertcode',
            '|'
        ]
    ];
    //添加一个用于统一图片管理的按钮
    UE.registerUI('images-manager', function (editor, uiName){
        //创建一个按钮
        return new UE.ui.Button({
            //按钮名称
            name: uiName,
            //提示
            title: "插入图片",
            //
            cssRules: "background-position: -380px 0;",
            //
            onclick: function () {
                vm.filesManagerOpen({
                    title: "插入图片",
                    okText: "确定",
                    cancelText: "取消",
                    type: "image",
                    multi: true,
                    ok: images => {
                        let imagesHtml = [];
                        images.forEach(item => {
                            if(item.type === 'image' && item.checked) {
                                imagesHtml.push('<p><img src="' + item.url + '" alt="' + item.name + '"></p>');
                            }
                        });
                        if(imagesHtml.length > 0){
                            editor.execCommand("insertHtml", imagesHtml.join("\r\n"));
                        }
                    }
                });
            }
        });
    });
    //添加一个用于统一图片管理的按钮
    UE.registerUI('files-manager', function (editor, uiName){
        //创建一个按钮
        return new UE.ui.Button({
            //按钮名称
            name: uiName,
            //提示
            title: "插入文件",
            //
            cssRules: "background-position: -620px -40px;",
            //
            onclick: function () {
                vm.filesManagerOpen({
                    title: "插入文件",
                    okText: "确定",
                    cancelText: "取消",
                    type: "all",
                    multi: true,
                    ok: files => {
                        let linkHtml = [];
                        files.forEach(item => {
                            if(item.checked) {
                                linkHtml.push('<a href="' + item.url + '" title="' + item.name + '">'+ item.name +'</a>');
                            }
                        });
                        if(linkHtml.length > 0){
                            editor.execCommand("insertHtml", linkHtml.join("<br>"));
                        }
                    }
                });
            }
        });
    });
</script>